import org.molamil.commons.ObjectUtil;

/**
 * Offers functionality to return a nested <code>MovieClip</code> by referencing it as a URI or a path.
 *
 * @author Jorge Hernandez
 */
class org.molamil.acto.mc.McTargetResolver {
	
	
	// Functions
	
	/**
	 * Gets a nested <code>MovieClip</code> by parsing a String as a path/URI.
	 * 
	 * @param   target path/URI that contains the target to the mc, examples:
	 * 			<ul>
	 * 				<li>/some_mc/target_mc/to_mc/myMovie_mc</li>
	 * 				<li>some_mc/target_mc/to_mc/myMovie_mc</li>
	 * 				<li>some_mc.target_mc.to_mc.myMovie_mc</li>
	 * 			</ul>
	 * 			The two first examples are similar.
	 * @param   mc [Optional] mc to search the nested mc from. If not passed, <code>_root</code> is used.
	 * @return  The nested <code>MovieClip</code>.
	 */
	public static function getMc(target:String, mc:MovieClip):MovieClip {
		
		if (mc == null)
			mc = _root;
		
		var ROOT:String = "_root.";
		var SLASH:String = "/";
		if (target.toLowerCase().indexOf(ROOT) == 0)
			target = target.substr(ROOT.length);
		if (target.toLowerCase().indexOf(SLASH) == 0)
			target = target.substr(SLASH.length);
			
		return MovieClip(ObjectUtil.getNestedProperty(mc, target));
		
	}
	
	
}